// ctx.tsx
'use client';
import { createContext, Dispatch, useReducer } from 'react';
import { userReducer, initialState, ACTIONS } from './reducer';
import { DataType } from './column';

// 定义 context 类型
export interface UserContextType {
  state: DataType[];
  dispatch: Dispatch<any>;
}

// 创建 context
export const UserContext = createContext<UserContextType>({
  state: [],
  dispatch: () => null
});

// Context Provider 组件
export const UserProvider = ({ children }: { children: React.ReactNode }) => {
  const [state, dispatch] = useReducer(userReducer, initialState);

  return (
    <UserContext.Provider value={{ state, dispatch }}>
      {children}
    </UserContext.Provider>
  );
};